﻿'use strict';

/*global module, exports, define, ActiveXObject*/
(function (global, factory) {
    if (typeof exports === 'object') {
        // Node
        module.exports = factory();
    }
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(
            [
                'baseClass',
                'response',
            ],
            factory);
    }
    
    //// Browser globals
    //global.utils = factory(BaseClass);

}(typeof window !== "undefined" ? window : this, function (BaseClass, Response) {
    var utils = {
        BaseClass: BaseClass,
        //editors: {

        //},
        misc: {
            s4: function () {
                return
                    Math.floor((1 + Math.random()) * 0x10000)
                        .toString(16)
                        .substring(1);
            },
            guid: function () {
                return function () {
                    return this.s4() + this.s4() + '-' + this.s4() + '-' + this.s4() + '-' + this.s4() + '-' + this.s4() + this.s4() + this.s4();
                };
            },
        },
        backend: {
            Response: Response,
        },
        templating: {
            load: function (url) {
                var that = this,
                    template,
                    fn_success = function (response) {
                        template = response;
                    };

                $.ajax({
                    url: url,
                    async: false,
                    dataType: 'html',
                    success: fn_success,
                });

                return template;
            },
        },
    };

    if (window)
        window.utils = utils;

    return utils;
}));